package com.crscd.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： liuziyang
 * @date： 2025/10/8-19:29
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RestController
public class RagController {
  @Qualifier("qwenChatClient")
  @Autowired
  private ChatClient chatClient;

  @Autowired private VectorStore vectorStore;

  @GetMapping("/rag4aiops")
  public Flux<String> rag(String question) {
    String systemInfo =
        """
            你是一个运维工程师，按照给出的编码先从本地知识库检索信息，如果检索成功，给出对应的解释，包括故障解释或正常状态说明，否则回复无法回答。                    。
        """;
    RetrievalAugmentationAdvisor advisor =
        RetrievalAugmentationAdvisor.builder()
            .documentRetriever(
                VectorStoreDocumentRetriever.builder().vectorStore(vectorStore).build())
            .build();
    return chatClient
        .prompt()
        .system(systemInfo)
        .user(question)
        .advisors(advisor)
        .stream()
        .content();
  }
}
